Problem changing enumerations on attribute type

Hi,

I wrote a script to change the enumerations of an attribute type. The goal was to get rid of a specific value. So, what I did was run through the modules, any usage of that value was changed to a value that was going to be kept. Then I modified the type, just leaving out the value to be done away with.

When I ran the script it wiped out all the values associated with the attribute that was using that type.

Did I do something that should have been obviously wrong to lose the data?

Best,
Frank
lanef - Thu Mar 14 17:48:18 EDT 2013

Re: Problem changing enumerations on attribute type
llandale - Fri Mar 15 12:15:40 EDT 2013

Yes this is tricky. You need to map the old values to the new. The AttrType "modify" takes a list arrays, the size of the arrays are the number of new enumerations.

So lets change "A, B, C, D" down to "A, C, D", removing enum "B":

int NumNew = 3   // we want to end up with 3 Enumerations
string Strings[NumNew] = {"A", "C", "D"}
int    Values [NumNew] = {1, 2, 3}  // whatever
int    Colors [NumNew] = {0, 0, 0}  // or is it "-1" for "no color"?
int    Mapping[NumNew] = {0, 2, 3}  // Old Enums A, B, C, D are in order 0, 1, 2, 3 respectively
      // The "2" in the above line means "C" is now position 1 but was previously position 2.


proceed from there.

AFTER changing the enums, do this to refresh all the objects:

 

  • for o in entire m do {o."NameAttr" = o."NameAttr"}


That should auto-remove all old references to "B".

-Louie

 

Re: Problem changing enumerations on attribute type
lanef - Mon Mar 18 09:38:18 EDT 2013

llandale - Fri Mar 15 12:15:40 EDT 2013

Yes this is tricky. You need to map the old values to the new. The AttrType "modify" takes a list arrays, the size of the arrays are the number of new enumerations.

So lets change "A, B, C, D" down to "A, C, D", removing enum "B":

int NumNew = 3   // we want to end up with 3 Enumerations
string Strings[NumNew] = {"A", "C", "D"}
int    Values [NumNew] = {1, 2, 3}  // whatever
int    Colors [NumNew] = {0, 0, 0}  // or is it "-1" for "no color"?
int    Mapping[NumNew] = {0, 2, 3}  // Old Enums A, B, C, D are in order 0, 1, 2, 3 respectively
      // The "2" in the above line means "C" is now position 1 but was previously position 2.


proceed from there.

AFTER changing the enums, do this to refresh all the objects:

 

  • for o in entire m do {o."NameAttr" = o."NameAttr"}


That should auto-remove all old references to "B".

-Louie

 

Hi,

Thank you Louie! I'm planning a retry (after fixing stuff by hand) using this technique. I would have never deduced this one from documentation!

Best,
Frank

Re: Problem changing enumerations on attribute type
llandale - Mon Mar 18 11:12:33 EDT 2013

lanef - Mon Mar 18 09:38:18 EDT 2013
Hi,

Thank you Louie! I'm planning a retry (after fixing stuff by hand) using this technique. I would have never deduced this one from documentation!

Best,
Frank

The documentation not only requires "deduction" but also "clairvoyance" and "zen serenety", lest it "induce" various unpleasant emotions. But then again it is a "reference" manual, not any sort of "tutorial".